package cn.edu.gzhmt.cart.domain;

import java.io.Serializable;
import java.math.BigDecimal;

import cn.edu.gzhmt.goods.domain.Goods;

/**
 * 购物车条目
 * @author azhuo
 *
 */
public class CartItem implements Serializable {

	private Goods goods; // 商品
	private int count; // 商品的数量

	public CartItem() {
	}

	public CartItem(Goods goods, int count) {
		this.goods = goods;
		this.count = count;
	}

	/**
	 * 条目小计
	 * 处理了二进制计算的误差问题
	 * @return
	 */
	public double getSubTotal() {

		BigDecimal pirce = new BigDecimal(goods.getPrice() + ""); // 单价
		BigDecimal count = new BigDecimal(this.count + ""); // 数量

		return pirce.multiply(count).doubleValue(); // 小计
	}

	public Goods getGoods() {
		return goods;
	}

	public void setGoods(Goods goods) {
		this.goods = goods;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	@Override
	public String toString() {
		return "CartItem [goods=" + goods + ", count=" + count + "]";
	}

}
